<!-- NewPracticeMasterApplyList_frame.html -->
<!-- NewPracticePostList_frame.html -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>岗位列表frame</title>
    <link rel="stylesheet" href="../../css/api.css" />
	<link rel="stylesheet" href="../../css/mui.min.css"/>
	<link rel="stylesheet" href="../../css/base.css"/>
	<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
	<link rel="stylesheet" href="../../css/newPractice.css">
	<style type="text/css">
		.content-div{
			padding: 0 14px;
		}
		.content-cell{
			border-radius: 10px;
			overflow: hidden;
			margin-bottom: 10px;
			position: relative;
		}
		.cell-bottom-div{
			background-color: white;
			padding: 10px;
		}
		.right-tag{
			font-size: 12px;
			line-height: 12px;
			padding: 4px 8px;
			color: white;
			border-radius: 4px;
			position: absolute;
			top: 10px;
			right: 20px;
			transform: scale(0.8,0.8);
		}
		.uncollect-tag{
			background-color: #44a6d6;
		}
		.collect-tag{
			background-color: #5bc432;
		}
		.content-cell .hot-news-title-img {
			width: 16px;
		}
		.post-tag{
			padding: 4px 10px;
			border: 1px solid #44a6d6;
			color: #44a6d6;
			font-size: 12px;
			line-height: 12px;
			border-radius: 10px;
			margin-right: 6px;
			margin-bottom: 6px;
		}
		.hot-news-title{
			position: relative;
		}
		.company-tag{
			float: right;
		}
		.sub-tag-div{
			display: inline;
			width: 50px;
			height: 18px;
			transform: rotate(45deg);
			position: absolute;
			top: -1px;
			right: -17px;
		}
		.sub-tag-status-0{
			/*background-color: #44a6d6;*/
			background-color: white;
		}
		.sub-tag-status-1{
			background-color: #5bc432;
		}
		.sub-tag-status-2{
			background-color: #eb535c;
		}
		.sub-tag-span{
			font-size: 12px;
			color: white;
			height: 14px;
			width: 50px;
			line-height: 14px;
			text-align: center;
			transform: scale(0.6);
			position: absolute;
			bottom: 0;
		}
	</style>
</head>
<body>
	<div id="tableview" class="content-div">
		<!-- <div class="content-cell">
			<div class="hot-news-title">
				<span class="base_dark_grey_shallow base_title_font hot-news-title-span">
					李存勖
				</span>
				<span class="post-tag company-tag">
					运输规划
				</span>
				<div class="sub-tag-div sub-tag-status-1">
					<span class="sub-tag-span">
						已通过
					</span>
				</div>
			</div>
		</div> -->
	</div>
	<div class="noSign" hidden="hidden" id="noData">
		<img src="../../image/icon_img.png" width="60%">
		<p class="font16 top_15 base_dark_grey" >
			暂无数据
		</p>
	</div>
	<div class="loadFailure" hidden="hidden" id="noNet">
		<img src="../../image/icon_img01.png" width="60%">
		<p class="" >
			数据加载失败
		</p>
		<p>
			请检查您的网络
		</p>
		<button type="button" class="mui-btn mui-btn-outlined" onclick="refreshData()">
			重新加载
		</button>
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/mui.min.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript" src="../../script/timeStampTool.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
	var page = 1;
	var rows = 20;
	var dropRefreshCount = 0;
	var applyArr = new Array();
	var currentApply = null
	apiready = function(){
		setupNotifi();
		loadData();
		setRefreshHeader();
		setPullUpRefresh();
	}
	function setupNotifi(){
		api.addEventListener({
		    name: 'postApplySucceedNotifi'
		}, function(ret, err) {
		    if (currentApply != null) {
		    	var applyData = ret.value;
		    	var practicestatus_id = applyData.practicestatus_id;
		    	if (practicestatus_id == currentApply.practicestatus_id) {
		    		var status = ret.value.apply_status;
		    		currentApply.apply_status = status;
		    		$('#'+practicestatus_id).append(applyTagHtml(status));
		    	}
		    }
		});
	}
	//下拉刷新
	function setRefreshHeader() {
		api.setRefreshHeaderInfo({
			visible : true,
			bgColor : '#ccc',
			textColor : '#fff',
			textDown : '下拉刷新...',
			textUp : '松开刷新...',
			showTime : true
		}, function(ret, err) {
			page = 1;
			loadData();
		});
	}
	// 上拉加载
	function setPullUpRefresh() {
		api.addEventListener({
			name : 'scrolltobottom'
		}, function(ret, err) {
			if (dropRefreshCount >= rows) {
				dropRefreshCount = 0;
				page++;
				loadData();
			}
		});
	}
	function loadData(){
		var params = {
			page : page,
			rows : rows,
			sfid : $api.getStorage('cfnetppuid'),
			jid : $api.getStorage('cfnetppjid')
		};
		if (page == 1) {
			api.showProgress({
			    style: 'default',
			    animationType: 'fade',
			    title: '数据加载中...',
			    text: '',
			    modal: false
			});
		}
		cfnetppPOST(url_newPracticeApplyList, params, true, function(data, status){
			api.refreshHeaderLoadDone();
			api.hideProgress();
			if (status == 'success') {
				if (data.code == 200) {
					if (page == 1) {
						applyArr = new Array();
						$('#tableview').html('');
					}
					var apply_list = data.data;
					if (apply_list != null && apply_list.constructor == Array) {
						dropRefreshCount = apply_list.length;
						$('#noData').hide();
						$('#noNet').hide();
						if (apply_list.length > 0) {
							var oldCount = applyArr.length;
							applyArr = applyArr.concat(apply_list);
							var newCount = applyArr.length;
							for (var i = oldCount; i < newCount; i++) {
								var apply  = applyArr[i];
								$('#tableview').append(applyCellHtml(i, apply));
							}
							setupApplyCellClick();
						}else{
							if (page == 1) {
								$('#noData').show();
								$('#noNet').hide();
								$('#tableview').html('');
								api.toast({
								    msg: data.message
								});
							}
						}
					}
				}else{
					api.toast({
					    msg: data.message
					});
					if (page == 1) {
						$('#noData').show();
						$('#noNet').hide();
						$('#tableview').html('');
					}
				}
			}else{
				api.toast({
				    msg: '网络异常'
				});
				if (page == 1) {
					$('#noData').hide();
					$('#noNet').show();
					$('#tableview').html('');
				}
			}
		});
	}
	function setupApplyCellClick(){
		$('.apply-cell').unbind('click');
		$('.apply-cell').click(function(){
			var index = $(this).attr('index');
			var applyData = applyArr[parseInt(index)];
			currentApply = applyData;
			api.openWin({useWKWebView:true,
			    name: 'NewPracticeApplyChangePost_Master_win',
			    url: 'NewPracticeApplyChangePost_Master_win.html',
			    pageParam: applyData
			});
		});
	}
	function applyCellHtml(index, data){
		var practicestatus_id = data.practicestatus_id;
		var uname = data.uname;
		var apply_status = data.apply_status;
		var post_name = data.post_name;
		var applyHtml = '';
		if (apply_status == 1 || apply_status == 2) {//已通过\已驳回
			applyHtml = applyTagHtml(apply_status);
		}
		return '<div index="'+index+'" class="content-cell apply-cell">\
					<div id="'+practicestatus_id+'" class="hot-news-title">\
						<span class="base_dark_grey_shallow base_title_font hot-news-title-span">'+
							uname+
						'</span>\
						<span class="post-tag company-tag">'+
							post_name+
						'</span>'+
						applyHtml+
					'</div>\
				</div>';
	}
	function applyTagHtml(status) {
		var className = "sub-tag-status-"+status;
		var tag = '';
		if (status == 1) {
			tag = "已通过";
		}else if(status == 2){
			tag = "已驳回";
		}
		return '<div class="sub-tag-div '+className+'">'+
					'<span class="sub-tag-span">'+
						tag+ 
					'</span>'+
				'</div>';
	}
</script>
</html>